package com.techthinker.dreamBuilder.Activitites;

import java.io.FileNotFoundException;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher.ViewFactory;

import com.techthinker.dreamBuilder.R;
import com.techthinker.dreamBuilder.Define.Constant;
import com.techthinker.dreamBuilder.widget.Learn_GalleryFlow;
import com.techthinker.dreamBuilder.widget.adpters.Learn_DicCoverAdapter;

public class LearnActivity extends Activity {
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// fullscreen mode
		int flag = WindowManager.LayoutParams.FLAG_FULLSCREEN;
		Window myWindow = this.getWindow();
		myWindow.setFlags(flag, flag);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);

		setContentView(R.layout.learn_galleryflow);

		// TextSwitcher
		final TextSwitcher dicCoverName = (TextSwitcher) this
				.findViewById(R.id.ts_learn_dic_cover_name);
		dicCoverName.setFactory(new ViewFactory() {
			public View makeView() {
				TextView tv = new TextView(LearnActivity.this);
				tv.setTextColor(0xFF552233);
				tv.setLayoutParams(new TextSwitcher.LayoutParams(
						LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
				tv.setTextSize(30);
				return tv;
			}
		});

		// DicCoverGallery
		final Learn_DicCoverAdapter dicCoverAdapter = new Learn_DicCoverAdapter(
				this);
		try {
			dicCoverAdapter.createReflectedImages();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		final Learn_GalleryFlow galleryFlow = (Learn_GalleryFlow) this
				.findViewById(R.id.gallery_learn_dic_cover);
		galleryFlow.setFadingEdgeLength(0);
		galleryFlow.setSpacing(Constant.CHILD_SPACE);
		galleryFlow.setAdapter(dicCoverAdapter);
		galleryFlow.setOnItemSelectedListener(new OnItemSelectedListener() {

			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {
				dicCoverName.setText(dicCoverAdapter.getItemDicName(position));
			}

			public void onNothingSelected(AdapterView<?> arg0) {

			}
		});

		galleryFlow.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				Intent toListSelect = new Intent();
				toListSelect.putExtra("dictionary_id", dicCoverAdapter.getItemDicId(position));
				toListSelect.setClass(LearnActivity.this,
						Learn_selectListActivity.class);
				startActivity(toListSelect);
			}
		});
		galleryFlow.setSelection(0);
		dicCoverName.setText(dicCoverAdapter.getItemDicName(galleryFlow
				.getSelectedItemPosition()));

	}

}
